<style>
.wrapper_image{
	width:50px;
	height:50px;
	float:left;
	padding:2px;
}
.wrapper_image .icon{
	border:1px solid #fff;
	cursor:pointer;
}

.wrapper_image .icon:hover{
	background-color:#8ff;
	border:1px solid #ccf;
	cursor:pointer;
}

.hightlight{
	background-color:#8ff;
	border:1px solid #ccf;
}

</style>
<div class="content">
	<div class="content_i">
    <?php
	   echo "<h2>";
			echo CHtml::image(Yii::app()->baseUrl."/assets/icon/icon-16-info.png");
			echo " Thông tin Admin Menu";
		echo "</h2>";
			
        echo CHtml::beginForm(
			array($controller_id."/save","adminmenu_id"=>$row->id),
			"post", 
			array("id"=>"form_edit")
		);
		echo "<table cellpadding='3' cellspacing='0 border='0' width='100%'>";
		
			echo "<tr>";
				echo "<td class='label' width='100'>"."Admin Menu"."</td>";
				echo "<td>";
				echo CHtml::textField("name", $row["name"], array('style'=>'width:400px'));
				echo "</td>";
			echo "</tr>";
			
			echo "<tr>";
				echo "<td class='label' width='100'>"."Route"."</td>";
				echo "<td>";
				echo CHtml::textField("route", $row["route"], array('style'=>'width:400px'));
				echo "</td>";
			echo "</tr>";
			
			echo "<tr>";
				echo "<td class='label' width='100'>"."Thứ tự"."</td>";
				echo "<td>";
				echo CHtml::textField("order", $row["order"], array('style'=>'width:400px'));
				echo "</td>";
			echo "</tr>";
			
			echo "<tr>";
				echo "<td class='label' width='100'>"."Mô tả"."</td>";
				echo "<td>";
				echo CHtml::textField("desc", $row["desc"], array('style'=>'width:400px'));
				echo "</td>";
			echo "</tr>";
			
			echo "<tr>";
				echo "<td class='label' width='100'>"."Hình ảnh"."</td>";
				echo "<td>";
				echo CHtml::textField("image", $row["image"], 
					array('style'=>'width:400px', 'id'=>'id_image'));
				echo "</td>";
			echo "</tr>";
			
			echo "<tr>";
				echo "<td class='label' width='100'>"."</td>";
				echo "<td>";
					echo "<div style='background-color:#fff; width:100%; 
						min-height:100px; border:1px solid #ddd; overflow:hidden;
						padding:5px 0 10px 0;'>";
					
						$dirs = dir(WEB_ROOT . "/".  ADMIN_FOLDER . "/assets/images/adminmenu");
						
						while($entry = $dirs->read())
						{
							if ($entry == '.' or $entry =='..')
								continue;
								
							$entry_path = WEB_ROOT . "/" . ADMIN_FOLDER . 
								"/assets/images/adminmenu/" .$entry;
							
							if ( ! is_dir($entry_path))
							{
								$photo = array();
								$filetype = strtolower(substr($entry, strrpos($entry,'.')+1));
								
								$filesize = filesize($entry_path);
								$photo["name"] = $entry;
								$photo["type"] = '.'.$filetype;
								$photo["size"] = $filesize;
								
								if ($filetype == "jpg" || $filetype == "png" || $filetype == "gif")
								{
									echo "<div class='wrapper_image'>";
									
									if ($row["image"] == $photo["name"])
									{
										echo CHtml::image(
											Yii::app()->baseUrl."/assets/images/adminmenu/". $photo["name"],
											$photo["name"],
											array("class"=>"icon hightlight", "title"=>$photo["name"])
										);
									}
									else
									{
										echo CHtml::image(
											Yii::app()->baseUrl."/assets/images/adminmenu/". $photo["name"],
											$photo["name"],
											array("class"=>"icon", "title"=>$photo["name"])
										);
									}
								
									echo "</div>";
								}
							}
						}
					echo "</div>";
				echo "</td>";
			echo "</tr>";
			
			echo "<tr>";
				echo "<td>"."</td>";
				echo "<td>";
					echo "<div class='space_5'></div>";

					echo 
						"<div class='button' id='button_submit'>" .
							"<div style='float:left; width:20px;'>" .
								CHtml::image(Yii::app()->baseUrl."/assets/icon/icon-16-save.png") .
							"</div>" .
							"<div style='float:left; min-width:40px;font-weight:bold'>".
								"Save & Close" .
							"</div>" .
						"</div>";
					
					echo 
						"<div class='button' id='button_savenew'>" .
							"<div style='float:left; width:20px;'>" .
								CHtml::image(Yii::app()->baseUrl."/assets/icon/icon-16-plus.png") .
							"</div>" .
							"<div style='float:left; min-width:40px;font-weight:bold'>".
								" Save & New" .
							"</div>" .
						"</div>";
					
					echo 
						"<div class='button' id='button_apply'>" .
							"<div style='float:left; width:20px;'>" .
								CHtml::image(Yii::app()->baseUrl."/assets/icon/icon-16-tick.png") .
							"</div>" .
							"<div style='float:left; min-width:40px;font-weight:bold'>".
								" Apply" .
							"</div>" .
						"</div>";
							
					echo 
						"<div class='button' id='button_cancel'>" .
							"<div style='float:left; width:20px;'>" .
								CHtml::image(Yii::app()->baseUrl."/assets/icon/icon-16-check.png") .
							"</div>" .
							"<div style='float:left; min-width:50px;font-weight:bold'>".
								"Cancel" .
							"</div>" .
						"</div>";
						
				echo "</td>";
			echo "</tr>";
				
		echo "</table>";
		echo CHtml::endForm();
	?>
    </div>
</div><!-- end div right -->

<script language="javascript">
	$(document).ready(function(){
		$('.icon').click(function(){
			var txt_image = document.getElementById("id_image");
			txt_image.value = this.alt;
			//alert(this.alt);
		});
	});
</script>

<script language="javascript">
$(document).ready(function(){

	$('#button_submit').click(function(){
		$('#form_edit').submit();
	});
	
	$('#button_savenew').click(function(){
		$('#form_edit').attr("action","<?php
			echo Yii::app()->createUrl(
				$this->module_id."/" . $this->controller_id."/savenew",
				array("adminmenu_id"=>$row["id"])
			);
		?>");
		$('#form_edit').submit();
	});
	
	$('#button_apply').click(function(){
		$('#form_edit').attr("action","<?php
			echo Yii::app()->createUrl(
				$this->module_id."/" . $this->controller_id."/apply",
				array("adminmenu_id"=>$row["id"])
			);
		?>");
		$('#form_edit').submit();
	});
	
	$('#button_cancel').click(function(){
		window.location = '<?php
			$url = Yii::app()->createUrl(
				$this->route . "/view"
			);
			echo $url;
		?>';
	});
});
</script>